package v1

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"jwgin/model/mysql"
	"jwgin/service"
)

type activity struct {
}

func (s *activity) Routers(Router *gin.RouterGroup) (R gin.IRoutes) {
	Router.GET("/activity", s.getAll)
	return Router
}

//获取活动列表
func (activity) getAll(c *gin.Context) {
	count, size, offset := pages(c)
	comid := c.GetUint("RoleID")
	if comid == 0 {
		RespErr(c, fmt.Errorf("系统用户认证失败"))
		return
	}
	db := service.G.Model(mysql.Activity{}).Where("comid = ?", comid)
	list := []map[string]interface{}{}
	db.Count(&count).
		Offset(offset).
		Limit(size).
		Order("id DESC").
		Scan(&list)
	RespList(c, count, list)
}
